<?php
// DECODED & NULLED BY DARKGOTH - NULLCAMP.COM

defined("PHPFOX") or exit("NO DICE!");

class Follow_Service_Follow extends Phpfox_Service
{
    private $_aException = array();
    private $_aPagesExceptionModule = array();
    public function __construct()
    {
        $this->_sTable     = phpfox::getT("follow");
        $this->_aException = array(
            "user",
            "core"
        );
    }
    public function getFilter($iUserId, $iItemId, $sType = 'user')
    {
        $aSupportModules = Phpfox::getService("follow.module")->getSupportModules($sType);
        if ($sType == "pages" && isset($aSupportModules["pages"])) {
            $aSupportModules["pages"]["title"] = "{phrase var='follow.pages_comments'}";
        }
        $aRow = $this->database()->select("ft.*")->from(Phpfox::getT("follow_filter"), "ft")->where("ft.user_id = " . (int) $iUserId . " and ft.type_id = \"" . $this->database()->escape($sType) . "\" and ft.item_id = " . (int) $iItemId)->execute("getSlaveRow");
        if (isset($aRow["feed_type"])) {
            $aTemp = unserialize($aRow["feed_type"]);
            foreach ($aSupportModules as $sModule => $aValue) {
                if (!isset($aTemp[$sModule])) {
                    $aSupportModules[$sModule]["is_selected"] = 1;
                } else {
                    $aSupportModules[$sModule]["is_selected"] = ($aTemp[$sModule]) ? 1 : 0;
                }
            }

        } else {
            foreach ($aSupportModules as $sModule => $aValue) {
                $aSupportModules[$sModule]["is_selected"] = 1;
            }
        }
        $aRow["filter"] = $aSupportModules;
        return $aRow;
    }
    public function setFilter($iUserId, $iItemId, $sType = 'user', $aVals = array(), $bIsInit = false)
    {
        $aFeedTypes = Phpfox::getService("follow.module")->getSupportModules();
        $aFilter    = array();
        $sCond      = "user_id = " . (int) $iUserId . " and type_id = \"" . $this->database()->escape($sType) . "\" and item_id = " . (int) $iItemId;
        $this->database()->delete(Phpfox::getT("follow_filter"), $sCond);
        if (!$bIsInit) {
            foreach ($aFeedTypes as $iKey => $aType) {
                $aFilter[$iKey] = (isset($aVals["filter"][$iKey])) ? 1 : 0;
            }
        } else {
            foreach ($aFeedTypes as $iKey => $aType) {
                $aFilter[$iKey] = 1;
            }
        }
        $aInsert = array(
            "user_id" => $iUserId,
            "item_id" => $iItemId,
            "type_id" => $sType,
            "feed_type" => serialize($aFilter),
            "get_noti" => (isset($aVals["noti"]) ? 1 : 0),
            "time_stamp" => PHPFOX_TIME
        );
        return $this->database()->insert(Phpfox::getT("follow_filter"), $aInsert);
    }
    public function getAllFilter($iUserId = 0, $bNoti = false)
    {
        $sCond = "ft.user_id = " . (int) $iUserId;
        if ($bNoti) {
            $sCond .= " and ft.get_noti = 1";
        }
        return $this->database()->select("ft.*")->from(Phpfox::getT("follow_filter"), "ft")->where($sCond)->execute("getSlaveRows");
    }
    public function getPending($sKeyword, $iUserId, $iOffset, $iAmount, $sType = 'user')
    {
        $sSuffix = (!empty($sKeyword) ? "  AND u2.full_name LIKE \"%" . Phpfox::getLib("parse.input")->clean($sKeyword) . "%\"" : "");
        $sCond   = "fp.item_id =" . $iUserId . $sSuffix . " AND fp.type_id = \"" . $this->database()->escape($sType) . "\"";
        $iCnt    = $this->database()->select("count(*)")->from(phpfox::getT("follow_pending"), "fp")->join(phpfox::getT("user"), "u", "u.user_id = fp.item_id")->join(Phpfox::getT("user"), "u2", "u2.user_id = fp.user_id")->where($sCond)->limit($iOffset, $iAmount)->execute("getSlaveField");
        $aRow    = $this->database()->select("fp.*, u2.*")->from(phpfox::getT("follow_pending"), "fp")->join(phpfox::getT("user"), "u", "u.user_id = fp.item_id")->join(Phpfox::getT("user"), "u2", "u2.user_id = fp.user_id")->where($sCond)->limit($iOffset, $iAmount)->execute("getSlaveRows");
        return array(
            $iCnt,
            $aRow
        );
    }
    public function getBlocker($iId, $iOffset = 0, $iAmount = 5, $sType = 'user', $sKeyword = '')
    {
        $sCond = "f.item_id = " . (int) $iId . " AND type_id = \"" . $this->database()->escape($sType) . "\"";
        if (!empty($sKeyword)) {
            $sCond .= " AND u.full_name LIKE \"\x25" . Phpfox::getLib("parse.input")->clean($sKeyword) . "%\"";
        }
        $iCnt  = $this->database()->select("count(f.id)")->from(Phpfox::getT("follow_block"), "f")->join(Phpfox::getT("user"), "u", "f.user_id = u.user_id")->where($sCond)->execute("getSlaveField");
        $aRows = $this->database()->select("f.*," . Phpfox::getUserField())->from(Phpfox::getT("follow_block"), "f")->join(Phpfox::getT("user"), "u", "f.user_id = u.user_id")->where($sCond)->limit($iOffset, $iAmount)->execute("getSlaveRows");
        return array(
            $iCnt,
            $aRows
        );
    }
    public function getFollowingList($iUserId = 0, $sType = 'user')
    {
        list($iCnt, $aRows) = $this->getFollowing($iUserId, 0, 0, $sType);
        $sReturn  = "-1";
        $sReturn2 = "-1";
        if ($aRows) {
            foreach ($aRows as $iKey => $aRow) {
                $sReturn .= "," . $aRow["user_id"];
            }
        }
        if ($sType == "user") {
            return $sReturn;
        }
        $aRows = $this->database()->select("u.user_id")->from(Phpfox::getT("user"), "u")->where("u.profile_page_id IN (" . $sReturn . ")")->execute("getSlaveRows");
        if ($aRows) {
            foreach ($aRows as $iKey => $aRow) {
                $sReturn2 .= "," . $aRow["user_id"];
            }
        }
        return ($sType == "user") ? $sReturn : $sReturn2;
    }
    public function getAvatar($aRow = array())
    {
        if (empty($aRow) || !isset($aRow["user_id"])) {
            return "";
        }
        $aTemp = Phpfox::getService("user")->get($aRow["user_id"]);
        return $aTemp["user_image"];
    }
    public function getFollower($iUserId, $iOffset = 0, $iAmount = 0, $sType = 'user', $sKeyword = '')
    {
        $sCond = "f.item_id = " . (int) $iUserId . " AND f.type_id = \"" . $this->database()->escape($sType) . "\"";
        if (!empty($sKeyword)) {
            $sCond .= " AND u.full_name LIKE \"%" . Phpfox::getLib("parse.input")->clean($sKeyword) . "%\"";
        }
        $iCnt = $this->database()->select("count(*) as amount")->from($this->_sTable, "f")->join(phpfox::getT("user"), "u", "u.user_id = f.user_id")->where($sCond)->execute("getSlaveField");
        if ($iAmount) {
            $this->database()->limit($iOffset, $iAmount);
        }
        $aRows = $this->database()->select("f.*," . Phpfox::getUserField())->from($this->_sTable, "f")->join(Phpfox::getT("user"), "u", "f.user_id = u.user_id")->where($sCond)->execute("getSlaveRows");
        return array(
            $iCnt,
            $aRows
        );
    }
    public function getFollowing($iUserId, $iOffset = 0, $iAmount = 0, $sType = 'user', $sKeyword = '')
    {
        $sCond = "f.user_id = " . (int) $iUserId . " AND f.type_id = \"" . $this->database()->escape($sType) . "\"";
        if (!empty($sKeyword)) {
            $sCond .= " AND u.full_name LIKE \"%" . Phpfox::getLib("parse.input")->clean($sKeyword) . "%\"";
        }
        $iCnt = $this->database()->select("count(*) as amount")->from($this->_sTable, "f")->join(Phpfox::getT("user"), "u", "f.item_id = u.user_id")->where($sCond)->execute("getSlaveField");
        if ($iAmount) {
            $this->database()->limit($iOffset, $iAmount);
        }
        $aRows = $this->database()->select("f.*," . Phpfox::getUserField())->from($this->_sTable, "f")->join(Phpfox::getT("user"), "u", "f.item_id = u.user_id")->where($sCond)->execute("getSlaveRows");
        return array(
            $iCnt,
            $aRows
        );
    }
    public function getOwnerItem($iItemId, $sType)
    {
        $aRow = array();
        if ($sType == "pages") {
            $aRow = $this->database()->select("item.*," . Phpfox::getUserField())->from(Phpfox::getT($sType), "item")->join(Phpfox::getT("user"), "u", "u.profile_page_id = item." . (($sType == "pages") ? "page" : $sType) . "_id")->where("item." . (($sType == "pages") ? "page" : $sType) . "_id = " . (int) $iItemId)->execute("getSlaveRow");
        } else {
        }
        return $aRow;
    }
    public function getFeedFromFollowing($iUserId = 0)
    {
        $aFilter         = $this->database()->select("ft.*")->from(Phpfox::getT("follow_filter"), "ft")->where("ft.user_id = " . (int) $iUserId)->execute("getSlaveRows");
        $aFeeds          = array();
        $sFeeds          = "-1";
        if (!empty($aFilter)) {
            $sParentCond = "";
            foreach ($aFilter as $iKey => $aEntry) {
                $sCond = "( ( ";
                if (!empty($aEntry["feed_type"])) {
                    $aEntry["feed_type"] = unserialize($aEntry["feed_type"]);
                    foreach ($aEntry["feed_type"] as $sModule => $iValue) {
                        if ($iValue) {
                            $sCond .= " feed.type_id LIKE \"\x25" . $sModule . "%\" OR";
                        }
                    }
                    $sCond = rtrim($sCond, "OR");
                    $sCond .= ") ";
                    if ($aEntry["type_id"] == "pages") {
                        $aItem = $this->getOwnerItem($aEntry["item_id"], $aEntry["type_id"]);
                        $sCond .= " AND (feed.parent_user_id = " . (int) $aEntry["item_id"];
                        $sCond .= " OR (feed.parent_user_id = 0 && feed.user_id = " . (int) $aItem["user_id"] . " ) ) )";
                    } else {
                        $sCond .= " AND feed.parent_user_id = 0 AND feed.user_id = " . (int) $aEntry["item_id"] . " )";
                    }
                    $sParentCond .= "OR " . $sCond;
                }
                $sParentCond = ltrim($sParentCond, "OR ");
            }
            $aFeeds = $this->database()->select("feed.*")->from(Phpfox::getT("feed"), "feed")->where("feed.privacy IN(0,1,2) AND " . $sParentCond)->execute("getSlaveRows");
        }
        if (!empty($aFeeds)) {
            $sFeeds = "-1";
            foreach ($aFeeds as $iKey => $aFeed) {
                $sFeeds .= "," . $aFeed["feed_id"];
                $this->database()->select("feed.*")->from(Phpfox::getT("feed"), "feed")->where("feed.feed_id IN(" . $sFeeds . ")")->union();
            }
        }
        return $aFilter;
    }
    public function isPage($iUserId = 0)
    {
        return $this->database()->select("user_id")->from(Phpfox::getT("user"), "u")->where("user_id = " . (int) $iUserId . " AND profile_page_id != 0")->execute("getSlaveField");
    }
    public function isFollow($iUserId, $iItemId = 0, $sType = 'user')
    {
        if (Phpfox::getUserId() == $iItemId && $sType == "user") {
            return true;
        }
        $iCnt = $this->database()->select("count(*)")->from($this->_sTable)->where("user_id = " . (int) $iUserId . " AND item_id = " . (int) $iItemId . " AND type_id = \"" . $this->database()->escape($sType) . "\"")->execute("getSlaveField");
        return ($iCnt > 0) ? true : false;
    }
    public function canFollow($iItemId, $sType = 'user')
    {
        if ($this->checkBlockAll($iItemId, $sType) || $this->checkBlockFollow($iItemId, Phpfox::getUserId(), $sType) || Phpfox::getService("user.block")->isBlocked($iItemId, Phpfox::getUserId())) {
            return false;
        }
        return true;
    }
    public function unBlock($iItemId, $iUserId, $sType = 'user')
    {
        return $this->database()->delete(phpfox::getT("follow_block"), "user_id = " . (int) $iUserId . " AND item_id = " . (int) $iItemId . " AND type_id = \"" . $this->database()->escape($sType) . "\"");
    }
    public function blockUser($iItemId, $iUserId, $sType = 'user')
    {
        if ($this->isUserExists($iUserId)) {
            $this->database()->delete($this->_sTable, "user_id = " . (int) $iUserId . " AND item_id = " . (int) $iItemId . " AND type_id = \"" . $this->database()->escape($sType) . "\"");
            $aInsert = array(
                "user_id" => $iUserId,
                "item_id" => $iItemId,
                "time_stamp" => PHPFOX_TIME,
                "type_id" => $sType
            );
            return $this->database()->insert(phpfox::getT("follow_block"), $aInsert);
        }
        return false;

    }
    public function alreadyBlock($iItemId, $iUserId, $sType = 'user')
    {
        $iCnt = $this->database()->select("count(*)")->from(phpfox::getT("follow_block"))->where("user_id = " . (int) $iUserId . " and item_id = " . (int) $iItemId . " and type_id = \"" . $this->database()->escape($sType) . "\"")->execute("getSlaveField");
        return ($iCnt > 0) ? true : false;
    }
    public function unFollow($iItemId, $iId, $sType = 'user')
    {
        if ($this->isUserExists($iId)) {
            $this->database()->delete($this->_sTable, "user_id = " . (int) $iId . " and item_id = " . (int) $iItemId . " and type_id =\"" . $this->database()->escape($sType) . "\"");
            $this->database()->delete(Phpfox::getT("follow_filter"), "user_id = " . (int) $iId . " and item_id = " . (int) $iItemId . " and type_id = \"" . $this->database()->escape($sType) . "\"");
            $this->database()->delete(Phpfox::getT("follow_filter"), "user_id = " . (int) $iId . " and item_id = " . (int) $iItemId . " and type_id =\"" . $this->database()->escape($sType) . "\"");
            $this->database()->delete(Phpfox::getT("follow_notification"), "user_id = " . (int) $iId . " and owner_id = " . (int) $iItemId . " and owner_type = \"" . $this->database()->escape($sType) . "\"");
            return true;
        }
        return false;
    }
    public function countFollower($iUserId, $sType = 'user')
    {
        return $this->database()->select("count(*)")->from($this->_sTable, "f")->where("f.item_id = " . $iUserId . " AND f.type_id = \"" . $this->database()->escape($sType) . "\"")->execute("getSlaveField");
    }
    public function countBlocker($iUserId, $sType = 'user')
    {
        return $this->database()->select("count(*)")->from(phpfox::getT("follow_block"))->where("item_id = " . $iUserId . " AND type_id = \"" . $this->database()->escape($sType) . "\"")->execute("getSlaveField");
    }
    public function countFollowing($iUserId, $sType = 'user')
    {
        return $this->database()->select("count(*)")->from($this->_sTable, "f")->where("f.user_id = " . $iUserId . " AND f.type_id = \"" . $this->database()->escape($sType) . "\"")->execute("getSlaveField");
    }
    public function checkBlockAll($iUserId, $sType = 'user')
    {
        $iId = $this->database()->select("item_id")->from(phpfox::getT("follow_block_all"))->where("item_id = " . (int) $iUserId . " AND type_id = \"" . $this->database()->escape($sType) . "\"")->execute("getSlaveField");
        return $iId;
    }
    public function checkBlockFollow($iItemId, $iUserId, $sType = 'user')
    {
        $iCnt = $this->database()->select("*")->from(phpfox::getT("follow_block"))->where("user_id = " . (int) $iUserId . " and item_id = " . (int) $iItemId . " AND type_id = \"" . $this->database()->escape($sType) . "\"")->execute("getSlaveRow");
        return $iCnt;
    }
    
    public function follow($iItemId, $sType = 'user')
    {
        if ($sType == "user") {
            if (!$this->isUserExists($iItemId)) {
                return false;
            }
        }
        if (!$this->canFollow($iItemId, $sType)) {
            return false;
        }
        $aSetting = Phpfox::getService("follow.process")->getSetting($iItemId, $sType);
        if ($aSetting["auto_approval"] == 1) {
            $aInsert = array(
                "user_id" => Phpfox::getUserId(),
                "item_id" => $iItemId,
                "type_id" => $sType,
                "time_stamp" => PHPFOX_TIME
            );
            $iId     = $this->database()->insert($this->_sTable, $aInsert);
            if (in_array($sType, array(
                "pages",
                "user"
            ))) {
                $aVals = array(
                    "item_id" => $iId,
                    "owner_user_id" => phpfox::getUserId(),
                    "time_stamp" => PHPFOX_TIME
                );
                if ($sType == "pages") {
                    $aVals["type_id"] = "follow_item";
                    $aPage            = Phpfox::getService("pages")->getPage($iItemId);
                    $aVals["user_id"] = $aPage["user_id"];
                } elseif ($sType == "user") {
                    $aVals["type_id"] = "follow";
                }
                $this->database()->insert(phpfox::getT("notification"), $aVals);
                $this->setFilter(Phpfox::getUserId(), $iItemId, $sType, array(), true);
            }

        } else {
            if (!Phpfox::getService("follow.process")->isPending($iItemId, $sType)) {
                $aInsert = array(
                    "user_id" => Phpfox::getUserId(),
                    "item_id" => $iItemId,
                    "type_id" => $sType,
                    "time_stamp" => PHPFOX_TIME
                );
                $iId     = $this->database()->insert(Phpfox::getT("follow_pending"), $aInsert);
                $aVals   = array(
                    "item_id" => $iId,
                    "owner_user_id" => phpfox::getUserId(),
                    "time_stamp" => PHPFOX_TIME
                );
                if ($sType == "pages") {
                    $aVals["type_id"] = "follow_waiting_item";
                    $aPage            = Phpfox::getService("pages")->getPage($iItemId);
                    $aVals["user_id"] = $aPage["user_id"];
                } elseif ($sType == "user") {
                    $aVals["type_id"] = "follow_waiting";
                    $aVals["user_id"] = $iItemId;
                }
                $this->database()->insert(phpfox::getT("notification"), $aVals);
            }
            if ($sType == "user") {
                $sLink = "follow";
            } elseif ($sType == "pages") {
                $sLink = "pages." . $iItemId . ".follow.follower";
            }
            Phpfox::getLib("url")->send($sLink, null, Phpfox::getPhrase("follow.waiting_for_this_user_approval"));
        }
        return true;
    }
    public function followAfterConfirm($iItemId, $sType, $iUserId)
    {
        $this->database()->delete(Phpfox::getT("follow_pending"), "user_id = " . (int) $iUserId . " AND item_id = " . (int) Phpfox::getUserId());
        $aInsert = array(
            "user_id" => $iUserId,
            "item_id" => $iItemId,
            "type_id" => $sType,
            "time_stamp" => PHPFOX_TIME
        );
        $iId     = $this->database()->insert($this->_sTable, $aInsert);
        $aVals   = array(
            "item_id" => $iId,
            "user_id" => $iUserId,
            "owner_user_id" => Phpfox::getUserId(),
            "time_stamp" => PHPFOX_TIME
        );
        if ($sType == "user") {
            $aVals["type_id"] = "follow_confirm";
        } else {
            $aVals["type_id"] = "follow_confirm_item";
        }
        $this->database()->insert(phpfox::getT("notification"), $aVals);
        $this->setFilter($iUserId, $iItemId, $sType, array(), true);
        return $iId;
    }
    public function denyFollow($iItemId, $sType, $iUserId)
    {
        return $this->database()->delete(Phpfox::getT("follow_pending"), "user_id = " . (int) $iUserId . " AND item_id = " . (int) Phpfox::getUserId());
    }
    public function isBlockAll($iId, $sType = 'user')
    {
        $iCnt = $this->database()->select("count(*)")->from(phpfox::getT("follow_block_all"))->where("item_id = " . (int) $iId)->execute("getSlaveField");
        return ($iCnt) > 0 ? true : false;
    }
    public function blockAll($iId, $sType = 'user')
    {
        if (!$this->hasPermission($iId, $sType)) {
            Phpfox::getLib("url")->send("follow", null, Phpfox::getPhrase("follow.you_do_not_have_permission_to_perform_this_action"));
        }
        $this->database()->delete($this->_sTable, "item_id = " . (int) $iId . "  AND type_id = \"" . $this->database()->escape($sType) . "\"");
        return $this->database()->insert(phpfox::getT("follow_block_all"), array(
            "item_id" => $iId,
            "type_id" => $sType
        ));
    }
    public function unBlockAll($iId, $sType = 'user')
    {
        if (!$this->hasPermission($iId, $sType)) {
            Phpfox::getLib("url")->send("follow", null, Phpfox::getPhrase("follow.you_do_not_have_permission_to_perform_this_action"));
        }
        return $this->database()->delete(phpfox::getT("follow_block_all"), "item_id = " . (int) $iId . " AND type_id = \"" . $this->database()->escape($sType) . "\"");
    }
    public function hasPermission($iId, $sType = 'user')
    {
        switch ($sType) {
            case "user":
                if ($iId != Phpfox::getUserId()) {
                    return false;
                }
                break;
            case "pages":
                if (Phpfox::getService("pages")->isAdmin($Id)) {
                    return false;
                }
                break;
        }
        return true;
    }
    public function getTopFollowing()
    {
        return $this->database()->select("user_id, count(item_id) as total_followers")->from($this->_sTable)->group("user_id")->order("total_followers DESC")->limit(Phpfox::getParam("follow.topfollowing"))->execute("getSlaveRows");
    }
    public function searchFollower($sKeyword, $iUserId, $iOffset, $iAmount, $sType = 'user')
    {
        $sCond = "u.full_name LIKE \"%" . Phpfox::getLib("parse.input")->clean($sKeyword) . "%\" AND f.item_id =" . (int) $iUserId . " AND f.type_id = \"" . $this->database()->escape($sType) . "\"";
        return $this->database()->select("f.*," . Phpfox::getUserField())->from($this->_sTable, "f")->join(phpfox::getT("user"), "u", "u.user_id = f.user_id")->where($sCond)->limit($iOffset, $iAmount)->execute("getSlaveRows");
    }
    public function countsearchFollower($sKeyword, $iUserId, $sType = 'user')
    {
    
    }
    public function searchFollowing($sKeyword, $iUserId, $iOffset, $iAmount, $sType = 'user')
    {
        $sCond = "u.full_name LIKE \"%" . Phpfox::getLib("parse.input")->clean($sKeyword) . "%\" AND f.user_id =" . (int) $iUserId . " AND f.type_id = \"" . $this->database()->escape($sType) . "\"";
        return $this->database()->select("f.*," . Phpfox::getUserField())->from($this->_sTable, "f")->leftJoin(phpfox::getT("user"), "u", "f.item_id = u.user_id ")->where($sCond)->limit($iOffset, $iAmount)->execute("getSlaveRows");
    }
    public function countsearchFollowing($sKeyword, $iUserId, $sType = 'user')
    {
        $sCond = "u.full_name LIKE \"%" . Phpfox::getLib("parse.input")->clean($sKeyword) . "%\" AND f.user_id =" . (int) $iUserId . " AND f.type_id = \"" . $this->database()->escape($sType) . "\"";
        return $this->database()->select("count(*) as amount")->from($this->_sTable, "f")->leftJoin(phpfox::getT("user"), "u", "f.item_id = u.user_id ")->where($sCond)->execute("getSlaveField");
    }
    public function searchBlocker($sKeyword, $iUserId, $iOffset, $iAmount, $sType = 'user')
    {
        $sCond = "u.full_name LIKE \"\x25" . Phpfox::getLib("parse.input")->clean($sKeyword) . "%\"\x20\x41\x4e\x44 b.\x69\x74\x65\x6d_\x69\x64\x20=" . (int) $iUserId . " AND b.type_id = \"" . $this->database()->escape($sType) . "\"";
        return $this->database()->select("b.*," . Phpfox::getUserField())->from(phpfox::getT("follow_block"), "b")->leftJoin(phpfox::getT("user"), "u", "u.user_id = b.user_id")->where($sCond)->limit($iOffset, $iAmount)->execute("getSlaveRows");
    }
    public function countsearchBlocker($sKeyword, $iUserId, $sType = 'user')
    {
        $sCond = "u.full_name LIKE \"%" . Phpfox::getLib("parse.input")->clean($sKeyword) . "%\"\x20\x41ND\x20\x62.ite\x6d\x5f\x69\x64 \x3d" . (int) $iUserId . " AND b.type_id = \"" . $this->database()->escape($sType) . "\"";
        return $this->database()->select("count(*) as amount")->from(phpfox::getT("follow_block"), "b")->leftJoin(phpfox::getT("user"), "u", "u.user_id = b.user_id")->where($sCond)->execute("getSlaveField");
    }
    public function isUserExists($iId)
    {
        $iCnt = $this->database()->select("count(*)")->from(Phpfox::getT("user"))->where("user_id = " . (int) $iId)->execute("getSlaveField");
        return ($iCnt > 0) ? true : false;
    }
    public function checkBlockUser($iUserId)
    {
        $aRows = $this->database()->select("*")->from(phpfox::getT("user_blocked"))->where("block_user_id = " . (int) $iUserId)->execute("getSlaveRows");
        if (count($aRows)) {
            foreach ($aRows as $aRow) {
                $this->database()->delete(phpfox::getT("follow"), "user_id = " . (int) $aRow["user_id"] . " and item_id = " . (int) $iUserId);
            }
        }
    }
}
?>